<?php

/**
 * @version 1.0
 * @created 08-Jun-2009 3:16:47 PM
 */
class UpdateRole
{

	static $dataValidator;

	function __construct()
	{
	}



	/**
	 * 
	 * @param role
	 */
	static function updateRole(Role $role)
	{
		// Instantiate the AmazonSDB class
		$sdb = new AmazonSDB();
		// Store the name of the domain
		$domain = ROLES_DOMAIN;
		// Create the domain
		$roles_domain = $sdb->domain_metadata( $domain );
		if ($roles_domain->isOK())
		{
			//encode the roles and put
			$roleObj = json_decode( json_encode( $role ), true );
			$roleObj["keys"] = implode(",", $roleObj["keys"] );
			$response = $sdb->put_attributes( $domain, $role->name, $roleObj, true );
			if ($response->isOK())
			{
				if( Cache::getInstance()->get("roles") != false ){
					//error_log("updating role in cache", 0);
					$roles = Cache::getInstance()->get("roles");
					$roles[$role->name] = $role;
					Cache::getInstance()->replace("roles", $roles, false, 86400);
				}
				return AwsUtils::parseResponse( $response );
			}else{
				return AwsUtils::parseError( $response );
			}
		}else{
			return AwsUtils::parseError( $roles_domain );
		}
	}

}
?>